var paginationTotal = 20;//记录总数
var paginationPageSize  = 200;
var sortColumn = "";
var sortMethod = "";
var isIE = 0;
if (+[1,]){//非IE
	isIE = 0;	
}else {//IE
	isIE = 1;
	
}
function CkAllPicking(o){
	$(o).is(":checked")?$("input[name='selected_picking_members[]']").attr("checked",true):$("input[name='selected_picking_members[]']").attr("checked",false);
}

var print_ok = false;
$(function(){
	var dayNamesMin =['日','一', '二', '三', '四', '五', '六'];
    var monthNamesShort = ['01月','02月','03月','04月','05月','06月','07月','08月','09月','10月','11月','12月'];
    $('#dateFrom,#dateTo').datepicker({
        dayNamesMin:dayNamesMin,
        monthNamesShort:monthNamesShort,
        changeMonth:true,
        changeYear:true,
        dateFormat:'yy-mm-dd',
        onClose: function(dateText, inst) {
        	//initData(0);
        }
    });
   
	initData(0);
	$("#confirmDialog").dialog({
		autoOpen:false,
		modal:true,
		show:"slide",
		width:600,
		buttons:{
			"<{$lang.close}>":function(){
				$(this).dialog("close");
			}
		}
	});
	$("#confirmDialog2").dialog({
		autoOpen:false,
		modal:true,
		show:"slide",
		height:400,
		width:400
	});
	$("#confirmDialog1").dialog({
		autoOpen:false,
		modal:true,
		show:"slide",
		width:600,
		buttons:{
			"<{$lang.ok}>":function(){					
				var vForm = $("#printForm").serialize();				
				loading();
				$(this).dialog("close");
			    $.ajax({
					url: "/product/off-shelf/create-ship-code/isIE/"+isIE,
			        async: false,
			        dataType: "json",
					type:"post",
					data:vForm,
			        success: function(json) {
						initData(0);	        	
						closeLoading();	
						var html = "";
						var count = 0;
						$.each(json,function(k,v){
							html+="<div>"+v.msg+"</div>";
						});						
						$("#confirmDialog").html(html).dialog("open");				
			        }
			    });
				
			},			
			"<{$lang.close}>":function(){
				$(this).dialog("close");
			}
		}
	});
	$(".search").click(function(){
		initData(0);
	});
	
	$(".print").click(function(){
		if($(".checked:checked").length == 0){
			$("#confirmDialog").html("<{$lang.pls}><{$lang.order}>").dialog("open");
			return false;
		}
		$("#confirmDialog1").dialog("open");			
	});
	
	$(".checkAll").click(function(){
		$(".checkAll").is(":checked")?$(".checked").attr("checked",true):$(".checked").attr("checked",false);
	});
	
	$(".sort").click(function(){
		sortColumn = $(this).attr("sortColumn");
		sortMethod = $(this).attr("sortMethod");
		$(".sort").children(".up").remove();
		if(sortMethod == 'asc'){
			$(this).attr("sortMethod","desc");
			$(this).append("<span class='up'>↑</span>");
		}else{
			$(this).attr("sortMethod","asc");
			$(this).append("<span class='up'>↓</span>");
		}
		
		initData(paginationCurrentPage-1);
	});
	
	//回车处理
	$("#customer_id").add("#orders_code").add("#<{$lang.sku}>").keyup(function(e){
		var key = e.which;
		if(key==13){
			initData(0);
		}
	});
});
function loadData(page, pageSize){
	
	$("#loadData").html('');
	var params = {"orders_code":$("[name=orders_code]").val(),"<{$lang.sku}>":$("[name=<{$lang.sku}>]").val(),"category":$("[name=category]").val(),"orderType":$("[name=orderType]").val(),"customer_id":$("[name=customer_id]").val(),"ship_type":$("[name=ship_type]").val(),"sortColumn":sortColumn,"sortMethod":sortMethod,"import_status":"0,2" };
	params.dateType = $("#dateType").val();
	params.dateFrom = $("#dateFrom").val();
	params.dateTo = $("#dateTo").val();
    $.ajax({
		url: "/product/off-shelf/list/page/" + page + "/pageSize/" + pageSize,
        async: false,
        dataType: "json",
		type:"post",
		data:params,
        success: function(data) {
            loading();
			var html="";
			var json = data.data;
			paginationTotal = data.count;
			if(json.length>0){
				$(".checkAll").attr("checked",true);//<{$lang.default}><{$lang.all}>选中
				var j = page == 1 ? 1 : pageSize * (page - 1) + 1;
				$.each(json,function(k,v){
					html += '<tr><td><input type="checkbox" class="checked" checked name="orderCode[]" value="'+v.orders_code+'"/></td><td>'+(k+1)+'</td><td><a href=\"javascript:detail(\'' + v.orders_code + '\')\">' + v.orders_code + '</a></td><td>'+v.customer_id+'</td><td>'+data.status[v.process_status]+'</td><td>'+v.shipping_method+'</td><td>'+v.customer_order_code+'</td><td>'+v.add_time+'</td><td>'+v.remark+'</td></tr>';
				});
			}else{
					html = '<tr><td colspan="9"><{$lang.no_data}></td></tr>';
			}
			
			
			$("#loadData").html(html);
			closeLoading();
        }
    });
}

//<{$lang.order}><{$lang.detail}>
function detail(orders_code) {
    var url = '/order/order/detail/orders_code/' + orders_code;
    window.open(url);
}